﻿using LCL.CodeHelper;
using LCL.IBuilder;
using LCL.LData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace LCL.Builder.SimpleFactory
{
    public partial class ProjectBuilder
    {
        #region BuilderWebMvc
        private void BuilderWebMvc()
        {
            string SourceDirectory = Utils.GetMapPath(@"Template\TemplatePro\WebMvc");
            string TargetDirectory = CodeCommon.DesktopDirectory + NameSpace + @"/WebMvc";
            CodeCommon.CopyDirectory(SourceDirectory, TargetDirectory);
            var tables = DbObject.GetTables(DbName);
            foreach (var table in tables)
            {
                var Fieldlist = DbObject.GetColumnInfoList(DbName, table.TableName);
                List<TableColumn> Keys = Fieldlist.Where(p => p.IsPrimaryKey == true).ToList();
                string className = CodeCommon.GetClassName(table.TableName, TableFormat);
                string ModelSpace = NameSpace + ".Model." + className;//命名空间 + 类名
                string DALSpace = NameSpace + ".DAL." + className;
                string IDALSpace = NameSpace + ".IDAL." + className;
                #region StringBuilder
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("using System; ");

                string filename = CodeCommon.DesktopDirectory + NameSpace + @"/WebMvc/Controllers/" + className + "Controller.cs";
                CodeCommon.CreateFiles(filename, builder.ToString());
                try
                {
                    VSProject.AddClass2012(CodeCommon.DesktopDirectory + NameSpace + @"/WebMvc/WebMvc.csproj", @"Controllers\" + className + "Controller.cs");
                }
                catch
                {
                }
                #endregion
            }
        }
        #endregion
    }
}
